- main_toolbar do |t|
  = t.edit resource
  = t.destroy

= cobbles do |c|
  - c.cobble :general_informations do
    = attributes_list do |l|
      - l.attribute :active
      - l.attribute :country
      - l.attribute :amount
      - l.attribute :nature
      - l.attribute :collect_account, url: true
      - l.attribute :deduction_account, url: true
      - l.attribute :fixed_asset_collect_account, url: true
      - l.attribute :fixed_asset_deduction_account, url: true
      - l.attribute :description

  - c.cobble :balance do
    :ruby
      stopped_at = Time.zone.now
      started_at = (stopped_at - 1.year).beginning_of_month

      series = []
      date = started_at
      periods = {}
      while date < stopped_at
        periods[date.l(format: "%b %Y")] = date..(date.end_of_month)
        date = date + 1.month
      end

      tax = resource

      collect_items   = tax.collect_account.journal_entry_items.between(started_at, stopped_at).reorder(:printed_on)
      deduction_items = tax.deduction_account.journal_entry_items.between(started_at, stopped_at).reorder(:printed_on)

      data = []
      last = {collect: 0.0, deduction: 0.0}
      for name, period in periods
        collect = collect_items.where(printed_on: period).last
        deduction = deduction_items.where(printed_on: period).last
        last[:collect] = (collect ? collect.cumulated_absolute_balance.to_f : last[:collect])
        last[:deduction] = (deduction ? deduction.cumulated_absolute_balance.to_f : last[:deduction])
        data << - (last[:collect] + last[:deduction])
      end
      series << {name: tax.name, data: data }
    = spline_highcharts(series, legend: { align: 'center', border_width: 0 }, x_axis: { title: {text: :months.tl}, categories: periods.keys}, y_axis: {title: {text: :amounts_in_currency.tl(currency: Preference[:currency])}})
